package com.afkt.project.ui.slice;


import com.afkt.project.base.app.BaseActivity;
import com.afkt.project.ui.adapter.ViewPagerAdapter;
import com.ohos.afkt.ResourceTable;
import com.dev.utils.app.toast.ToastTintUtils;
import com.dev.widget.custom.CustomViewPager;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;
import java.util.ArrayList;
import java.util.List;

public class ViewPagerActivity extends BaseActivity {
    private CustomViewPager vidAvpViewpager;

    private Button vidAvpAllowBtn;

    private Button vidAvpBanBtn;
    private DirectionalLayout bar_Layout;
    private DirectionalLayout bar;
    private Image select_retuen;


    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);


    }

    @Override
    protected int baseLayoutId() {
        return ResourceTable.Layout_activity_view_pager;
    }

    @Override
    protected void initView() {
        bar_Layout = (DirectionalLayout) findComponentById(ResourceTable.Id_base_view_barLayout);
        bar = (DirectionalLayout) LayoutScatter.getInstance(this).parse(ResourceTable.Layout_sheet_dialog_bar, null, false);
        Text text = (Text) bar.findComponentById(ResourceTable.Id_titleText);
        select_retuen = (Image) bar.findComponentById(ResourceTable.Id_sheet_dialog_return);
        text.setText("ViewPager 滑动监听、控制滑动");
        bar_Layout.addComponent(bar);
        vidAvpViewpager = (CustomViewPager) findComponentById(ResourceTable.Id_vid_avp_viewpager);
        vidAvpBanBtn = (Button) findComponentById(ResourceTable.Id_vid_avp_ban_btn);
        vidAvpAllowBtn = (Button) findComponentById(ResourceTable.Id_vid_avp_allow_btn);
        initValue();
    }

    @Override
    protected void initListener() {
        select_retuen.setClickedListener(component -> {
            // LogUtils.error(TAG, "return 点击");
            onBackPressed();
        });
    }

    @Override
    protected void onBackground() {
        super.onBackground();
        bar_Layout.removeAllComponents();
    }

    private void initValue() {
        List<String> lists = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            lists.add(new Integer(i).toString());
        }
        vidAvpViewpager.setProvider(new ViewPagerAdapter(lists));
        vidAvpViewpager.setCurrentPage(lists.size() * 100, true);
        vidAvpViewpager.addPageChangedListener(new CustomViewPager.OnDirectionListener() {
            @Override
            public void onSlideDirection(boolean left, boolean right) {

            }

            @Override
            public void onPageChosen(int i) {
                if (mLeftScroll) {
                    ToastTintUtils.success("往左滑 - 从右往左");
                } else {
                    ToastTintUtils.success("往右滑 - 从左往右");
                }
            }
        });

        vidAvpAllowBtn.setClickedListener(component -> {
            vidAvpViewpager.setSlide(true);
            ToastTintUtils.success("已允许滑动");
        });

        vidAvpBanBtn.setClickedListener(component -> {
            vidAvpViewpager.setSlide(false);
            ToastTintUtils.error("已禁止滑动");
        });
    }
}
